package com.azt.service.wechat;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import com.azt.utils.CommonUtil;

/**
 * 微信相关常量
 * Created by LiQZ on 2017/3/28.
 */
public class WeChatConstant {

    public static final String WEB_APP_ID = "wx3d115708ad806b8e";//订阅号appId

    public static final String MOBILE_APP_ID = "wxbb0a7ef088e6612c";//服务号appId
    
    public static final String MOBLE_SECRET="6e8d93e5ed0b59dd8b40982997117cda";//服务号密钥

    public static final String APP_SECRET = "1371336748ee41bc74fe4672147978ef";//订阅号密钥
    
    public static final String SECRET = "a7bd6544ca9d4bca809a9f13062d3796";//老版本，应该是测试扫描二维码密钥
    //弹框授权
    private static final String SHOW_WECHAT_DIALOG = "https://open.weixin.qq.com/connect/qrconnect?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_login";
    //静默授权
    private static final String SHOW_WECHAT_SNSAPI_BASE = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base#wechat_redirect";
    //用户确认
    private static final String SHOW_WECHAT_USER_INFO = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_userinfo#wechat_redirect";

    public static final String REDIRECT_URL = CommonUtil.MASTER_WEBSITE_URL+"/pressconference/addconferenceadmin?secret=a7bd6544ca9d4bca809a9f13062d3796";

    public static final String QRCODE_REDIRECT_URL = CommonUtil.MASTER_WEBSITE_URL+"/pressconference/scanseatqrcode?id=%d";//运营扫描二维码后，客户跳转路径，显示座位号等信息"

    public static final Boolean AUTH=false;//授权登陆开关
    
    /**
     * 调出 WeChat 的扫码框
     */
    public static String getShowWechatDialog(String redirectUrl) {
        try {
            return String.format(SHOW_WECHAT_DIALOG, WEB_APP_ID, URLEncoder.encode(redirectUrl, "utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    
    /** 
     * @Title: getShowWechatBase 
     * @Description: 静默
     * @param redirectUrl
     * @return
     * @return: String
     * @author: 查恒 2017年3月31日 下午3:26:05 
     */
    public static String getShowWechatBase(String redirectUrl) {
        try {
            return String.format(SHOW_WECHAT_SNSAPI_BASE, MOBILE_APP_ID, URLEncoder.encode(redirectUrl, "utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 生成带认证的回调函数
     */
    public static String getQRCodeRedirectUrl(Integer id) {
        return String.format(QRCODE_REDIRECT_URL, id);
    }

    public static void main(String[] args) {
        System.out.println(getShowWechatDialog(REDIRECT_URL));
    }


}
